<template>
    <noticeDetail ref="noticeDetail" />
    <noticePersonal ref="noticePersonal" />
    <el-container style="min-height: calc(100vh - 70px);">
        <el-main>
            <div class="teacher">
                <div class="app-table">
                    <div class="app-body">
                        <div class="app-search">
                            <el-form :inline="true" class="demo-form-inline" v-model="form">
                                <el-form-item label="标题">
                                    <el-input placeholder="请输入标题" v-model="form.title"
                                        @keyup.enter="searchEnter"></el-input>
                                </el-form-item>
                                <el-form-item>
                                    <el-button class="serach_btn" type="primary" plain @click="onSubmit">搜索</el-button>
                                    <el-button class="add_btn" type="success" plain @click="add">添加</el-button>
                                    <!-- <el-button type="warning" plain @click="exportExcel">导出报表</el-button> -->
                                </el-form-item>
                            </el-form>
                        </div>
                        <el-table :data="list" size="default" style="width: 100%;" :row-class-name="tableRowClassName">
                            <el-table-column prop="id" label="序号" width="60" />
                            <el-table-column prop="title" label="标题" />
                            <el-table-column prop="publishDate" label="发布日期" />

                            <el-table-column label="操作" width="350px">
                                <template #default="scope">
                                    <el-button class="edit_btn" type="success"
                                        @click="lookTeacher(scope.row)">接收人员</el-button>
                                    <el-button class="edit_btn" type="success"
                                        @click="lookOver(scope.row)">查看详情</el-button>
                                    <el-button class="edit_btn" type="success"
                                        @click="editApp(scope.row)">编辑</el-button>
                                    <el-button class="del_btn" type="danger"
                                        @click="deleteApp(scope.row.id)">删除</el-button>
                                </template>
                            </el-table-column>

                            <template v-slot:empty>
                                <el-empty description="暂无数据"></el-empty>
                            </template>
                        </el-table>
                        <el-config-provider :locale="locale">
                            <el-pagination :total="total" :page-size="limit" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                                layout="total, sizes, prev, pager, next, jumper" @size-change="changePageSize"
                                @current-change="changeCurrentPage">
                            </el-pagination>
                        </el-config-provider>
                    </div>
                    <bottomView />
                </div>
            </div>
        </el-main>
    </el-container>
</template>

<script>
import noticeDetail from "@/components/notice/noticeDetail.vue";
import bottomView from "@/components/bottom.vue";
import noticePersonal from "@/components/notice/noticePersonal.vue";
import { ElConfigProvider, ElMessageBox, ElMessage } from "element-plus";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { httpService } from "@/utils/httpService";
import { Picture as IconPicture } from "@element-plus/icons-vue";


export default {
    name: "BaseTeacherList",

    data() {
        return {
            type: 0,
            title: "",
            page: 1,
            pageSize: 10,
            total: 0,
            limit: 10,
            list: [],
            flagId: '',
            form: {
                title: "",
            },
            selectData: {},
            mobileNumber: '',
        };
    },
    components: {
        IconPicture,
        ElConfigProvider,
        ElMessageBox,
        ElMessage, noticeDetail,
        bottomView, noticePersonal,
    },
    watch: {
    },
    setup() {
        return {
            locale: zhCn,
        }
    },
    mounted() {
        this.getNoticeList();
    },
    watch: {
        $route() {
            this.getNoticeList();
        },
    },
    methods: {
        searchEnter: function (e) {
            console.log(e);
            // 使用 which 和 keyCode 属性来解决兼容问题
            var keyCode = window.event ? e.keyCode : e.which;
            var val = e.target.value;
            if (keyCode == 13 && val) {
                this.getNoticeList();
            }
        },
        add() {
            this.$router.push({ path: '/noticeIndexView/noticePublishView' })
            // this.$refs.addBaseTeacherView.title = "添加" + this.title
            // this.$refs.addBaseTeacherView.personnelType = this.type
            // this.$refs.addBaseTeacherView.dialogFormVisible = true;
            // this.$refs.addBaseTeacherView.getBaseRole()
        },
        editApp(obj) {
            this.$router.push({ path: '/noticeIndexView/noticePublishView', query: { id: obj.id } })
            // this.$refs.editBaseTeacherView.title = "修改信息"
            // this.$refs.editBaseTeacherView.getBaseTeacherById(obj.id);
            // this.$refs.editBaseTeacherView.getBaseRole();
            // this.$refs.editBaseTeacherView.dialogFormVisible = true;
        },
        lookOver(obj) {
            // this.$router.push({ path: '/noticeIndexView/NoticeDetailView', query: { id: obj.id } })
            this.$refs.noticeDetail.title = "查看详情";
            this.$refs.noticeDetail.dialogFormVisible = true;
            this.$refs.noticeDetail.queryNotice(obj.id)
            this.$refs.noticeDetail.readhandle(obj.id)
        },
        deleteApp(id) {
            ElMessageBox.confirm("确定要删除本条记录吗？", "提醒", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    httpService("/javaApi/messages/deleteById", "id=" + id, "post").then(
                        (data) => {
                            if (data.code == 200) {
                                ElMessage.success("删除成功");
                                this.getNoticeList();
                            } else {
                                ElMessage.error(data.message);
                            }
                        }
                    );
                })
                .catch(() => { });
        },
        onSubmit() {
            this.getNoticeList();
        },
        // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
        changePageSize(size) {
            this.pageSize = size;
            this.limit = size;
            this.getNoticeList();
        },

        // 改变页码，page：回调参数，表示当前选中的“页码”
        changeCurrentPage(page) {
            this.page = page;
            this.getNoticeList();
        },
        tableRowClassName({ row, rowIndex }) {
            return "";
        },
        getNoticeList() {
            httpService(
                "/javaApi/messages/list/" + this.page + "/" + this.pageSize,
                {
                    title: this.form.title
                },
                "get"
            ).then((data) => {
                this.list = data.list;
                this.total = data.total;
                this.pageCount = data.pages;
            });
        },
        lookTeacher(data) {
            console.log(this.$refs.noticePersonal);
            this.$refs.noticePersonal.title = "接收人员";
            this.$refs.noticePersonal.dialogFormVisible = true;
            this.$refs.noticePersonal.queryId = data.id;
            this.$refs.noticePersonal.getListmy()
            this.$refs.noticePersonal.lookTeacher(data.id)
            // httpService(
            //     "/javaApi/messageRecipients/list/1/2000",
            //     { messageId: data.id }, "get"
            // ).then((data) => {
            //     console.log(data);
            // });
        },
    },
};
</script>

<style scoped>
.el-main {
    padding: 0px;
    text-align: left
}

.teacher-content {
    width: 100%;
}

.app-table {
    background: #eff3f5;
    padding: 5px 10px 10px;
}

.app-separator {
    padding-top: 10px;
    padding-bottom: 20px;
    padding-left: 10px;
}

.app-body {
    background: white;
    padding: 10px 20px 10px 20px;
    margin-bottom: 10px;
    min-height: calc(100vh - 198px);
}

.el-table .warning-row {
    --el-table-tr-bg-color: var(--el-color-warning-lighter);
}

.el-table .success-row {
    --el-table-tr-bg-color: var(--el-color-success-lighter);
}

.el-pagination {
    text-align: center;
    margin-top: 10px;
}

.serach_btn {
    background-color: #007EFF;
    color: #fff;
    border-radius: 8px;
    border: none;
}

.add_btn {
    background-color: #00c78c;
    color: #fff;
    border-radius: 8px;
    border: none;
}

.edit_btn {
    background-color: #fff;
    color: #00c78c;
    border: none;
}

.del_btn {
    background-color: #fff;
    color: #FF0000;
    border: none;
}

.face_btn {
    background-color: #fff;
    color: #ff8400;
    border: none;
}

.retire_btn {
    background-color: #fff;
    color: #007EFF;
    border: none;
}
</style>